<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><{:C('web_site_name')}>--后台日志管理</title>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/main.css"/>

    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/jquery.js"></script>
    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/lib.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/layer.min.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/admin.js"></script>
</head>
<body>
<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>首页<span class="crumb-step">&gt;</span><span class="crumb-name">后台日志管理</span></div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                <form action="#" method="post">
                    <table class="search-tab">
                        <tr>
                           <th width="70">日志表:</th>
                            <td>
                                <select name="table"  id="table">
                                    <?php 
                                        if(isset($table) && $table){
                                            foreach ($table as $k => $v ){
                                        
                                    ?>
                                    <option value="<?php echo $v ; ?>"><?php echo $v ; ?></option>
                                    <?php } }?>
                                </select>

                            </td>
                            <th width="70">操作url:</th>
                            <td><input class="common-text" placeholder="操作的url例如nav/index" name="log_url" value="" id="log_url" type="text"></td>
                            <th width="70">操作者：</th>
                            <td><input class="common-text" placeholder="" name="log_person" value="" id="log_person" type="text"></td>   
                            <th width="70">状态：</th>
                            <td>
                                <select name="status" id="status">
                                <option value="all">请选择</option>
                                <option value="1">成功</option>
                                <option value="0">失败</option>
                               </select>
                            </td>     
                            <td><input class="btn btn-primary btn2" name="sub" value="查询" type="button" onclick="search()"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
               
                 <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                <div class="result-content">
                    <table class="result-tab" width="100%" >
                        <tr>
                            <th>编号</th>
					        <th>用户名</th>
					        <th>操作地址</th>
					        <th >添加日期  </th>
					        <th >操作ip </th>
					        <th>状态</th>
					        <th>操作sql</th>
					        <th>描述</th>
                        </tr>
                      <tbody id="result_"></tbody>
                        
                    </table>
                    
                        
                    <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                </div>
            </form>
        </div>
</body>
</html>
<script>
var loadding_0  ;
var page = 1 ;
$(function () {
    common_request();
});
function common_request(){
    if($("select[name='table']").val()== '' || $("select[name='table']").val()== null){
        layer.msg("暂无数据，没有操作日志表");
        return false ;
    }
    var url="<?php echo U("log/index");?>&inajax=1";
    var data_ = {
        'page':page,
        'time':<?php echo time();?>,
        'action':'ajax_data' , 
        'log_person':$("input[name='log_person']").val() , 
        'log_url':$("input[name='log_url']").val() , 
        'status':$("select[name='status']").val() ,
        'table':$("select[name='table']").val()
    } ;
    //console.dir(data_);
    $.ajax({
    type: "POST",
    url: url ,
    data: data_,
    cache:false,
    dataType:"json",
    // async:false,
    success: function(msg){
        var shtml = '' ;
        var list = msg.resultinfo.list;
        
        if(msg.resultcode!=1){
        	layer.msg(msg.resultinfo.errmsg);
            return false ;
        }else{
        	for(var i in list){
				shtml+='<tr>';
				shtml+= '<td>'+list[i].log_id+'</td>' ;
				shtml+='<td>'+list[i]['log_person']+'</td>';
				shtml+='<td>'+list[i]['log_url']+'</td>';
				shtml+='<td >'+list[i]['log_time']+'</td>';
				shtml+='<td>'+list[i]['log_ip']+'</td>';
				shtml+='<td>'+list[i]['log_status']+'</td>';
				shtml+='<td><a href="javascript:void(0)" onclick="getsql(this)" attr_sql="'+list[i]['log_sql_all']+'">'+list[i]['log_sql']+'</a></td>';
				shtml+='<td>'+list[i]['log_message']+'</td>';
				shtml+='</tr>';
			}

            $("#result_").html(shtml);
            $(".list-page").html(msg.resultinfo.obj);
        }
        layer.close(loadding_0);
    },
    beforeSend:function(){
         loadding_0 = layer.load('数据正在加载中。。。。。。'); 
    },
    error:function(){
        layer.msg('服务器繁忙请稍后');
        return false ;
    }
    });
}
function ajax_data(p){
    page = p  ; 
    common_request();
}
function search(){
    page = 1 ;
    common_request();
}


function getsql(o){
	var sql = $(o).attr("attr_sql");
	sql =str_decode(sql);
	layer.tips(sql, o, {
	    style: ['background-color:#78BA32; color:#fff', '#78BA32'],
	    maxWidth:285,
	    time: 5,
	    closeBtn:[0, true]
	});
	
}

</script> 

